// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   MenuDaoImpl.java

package com.hfstu.ifs.dataaccess.dao.impl;

import com.hfstu.framework.core.orm.Page;
import com.hfstu.framework.core.orm.PageRequest;
import com.hfstu.framework.core.orm.hibernate.PageDAOSpringTemplate;
import com.hfstu.framework.util.StringUtil;
import com.hfstu.ifs.dataaccess.dao.IMenuDao;
import java.util.*;
import org.hibernate.FetchMode;
import org.hibernate.criterion.*;

public class MenuDaoImpl extends PageDAOSpringTemplate
	implements IMenuDao
{

	public MenuDaoImpl()
	{
	}

	private DetachedCriteria defaultCriteria()
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass(), "menu");
		criteria.createAlias("nodeSystem", "sd");
		criteria.setFetchMode("nodeSystem", FetchMode.JOIN);
		return criteria;
	}

	public List findListByCondition(Map filterPropertyMap, Map sortValueMap)
	{
		DetachedCriteria criteria = defaultCriteria();
		if (filterPropertyMap != null && !filterPropertyMap.isEmpty())
		{
			Object value = null;
			Set keys = filterPropertyMap.keySet();
			for (Iterator iterator = keys.iterator(); iterator.hasNext();)
			{
				String key = (String)iterator.next();
				value = filterPropertyMap.get(key);
				if (key.equals("menu.name") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.like(key, (new StringBuilder("%")).append(value).append("%").toString()));
				if (key.equals("menu.parentId") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.eq(key, value));
				if (key.equals("sd.code") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.eq(key, value));
				if (key.equals("menu.ids"))
					criteria.add(Restrictions.in("menu.id", (Object[])value));
				value = null;
			}

		}
		if (sortValueMap != null && !sortValueMap.isEmpty())
		{
			Set keys = sortValueMap.keySet();
			for (Iterator iterator1 = keys.iterator(); iterator1.hasNext();)
			{
				String key = (String)iterator1.next();
				String value = (String)sortValueMap.get(key);
				if (!StringUtil.isNullOrEmpty(key) && !StringUtil.isNullOrEmpty(value))
				{
					if (value.equalsIgnoreCase("desc"))
						criteria.addOrder(Order.desc(key));
					if (value.equalsIgnoreCase("asc"))
						criteria.addOrder(Order.asc(key));
				}
			}

		}
		return super.findListByCriteria(criteria);
	}

	public Page findPageByCondition(PageRequest pageRequest, Map filterPropertyMap, Map sortValueMap)
	{
		StringBuilder hql = new StringBuilder();
		hql.append("from Menu menu");
		return super.findPageByCondition(pageRequest, hql.toString(), filterPropertyMap, sortValueMap);
	}

	public void deleteByIds(String ids[])
	{
		String as[];
		int j = (as = ids).length;
		for (int i = 0; i < j; i++)
		{
			String id = as[i];
			deleteEntity(id);
		}

	}
}
